# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/26 下午4:34
 @Author  : tgy
 
"""
from collections import deque

class Seem:
    __slots__ = ['content','history']

    def __init__(self,content,max_len=3):
        self.content = content
        self.history = deque(maxlen=max_len)

    def __iter__(self):
        for i, con in enumerate(self.content,1):
            yield con
            self.history.append((i, con))


    def clear(self):
        self.history.clear()


def read(path):
    ...
    with open(path,mode='rt', encoding='utf-8') as f:
        ...
        seem = Seem(f)
        for content in seem:
            if 'enumerate' in content:
                ...
                for i,con in seem.history:
                    print(i,con,end='')
                seem.clear()


if __name__ == '__main__':
    ...
    read('./4.5 反向迭代.py')